package com.xrit.controller;

import com.xrit.constant.RedisMessageConstant;
import com.xrit.utils.QiNiuUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Iterator;
import java.util.Set;

@ContextConfiguration(locations = "classpath:spring-redis.xml")
@RunWith(SpringJUnit4ClassRunner.class)
public class test {

    @Autowired
    private JedisPool jedisPool;

    @Test
    public void testDEl(){
        //1.获取Jedis对象
        Jedis jedis = jedisPool.getResource();
        //2.差集（垃圾图片）
        Set<String> sdiff = jedis.sdiff(RedisMessageConstant.SETMEAL_PIC_RESOURCES, RedisMessageConstant.SETMEAL_PIC_DB_RESOURCES);
        //3.迭代集合
        Iterator<String> iterator = sdiff.iterator();
        while(iterator.hasNext()){
            String imgName=iterator.next();
            //3.1 使用七牛云删除图片
            QiNiuUtils.removeFiles(imgName);
            //3.2 同事redis中也需要删除
            jedis.srem(RedisMessageConstant.SETMEAL_PIC_RESOURCES,imgName);
        }
        //4.关闭数据库
        jedis.close();
    }

    public static void main(String[] args) {
        System.out.println(getValue(2));
        System.out.println(Math.round(-11.2));
    }
    public static int getValue(int i){
        int result=0;
        switch(i){
            case 1:
                result=result +i;
            case 2:
                result=result+i*2;
            case 3:
                result=result+i*3;
        }
        return result;
    }
}
